package com.spic.business.riskbase.hierarchy.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.business.riskbase.hierarchy.domain.RiskDangerSource;
import com.spic.business.riskbase.hierarchy.service.IRiskDangerSourceService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.page.TableDataInfo;

/**
 * dangerSourceController
 *
 * @author ruoyi
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/risk/dangerSource")
public class RiskDangerSourceController extends BaseController
{
    @Autowired
    private IRiskDangerSourceService riskDangerSourceService;

    /**
     * 查询dangerSource列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RiskDangerSource riskDangerSource)
    {
        startPage();
        List<RiskDangerSource> list = riskDangerSourceService.selectRiskDangerSourceList(riskDangerSource);
        return getDataTable(list);
    }

    /**
     * 导出dangerSource列表
     */
    @Log(title = "dangerSource", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskDangerSource riskDangerSource) throws IOException {
        List<RiskDangerSource> list = riskDangerSourceService.selectRiskDangerSourceList(riskDangerSource);
        ExcelUtil<RiskDangerSource> util = new ExcelUtil<RiskDangerSource>(RiskDangerSource.class);
        util.exportExcel(response, list, "dangerSource数据");
    }

    /**
     * 获取dangerSource详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(riskDangerSourceService.selectRiskDangerSourceById(id));
    }

    /**
     * 新增dangerSource
     */
    @Log(title = "dangerSource", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskDangerSource riskDangerSource)
    {
        return toAjax(riskDangerSourceService.insertRiskDangerSource(riskDangerSource));
    }

    /**
     * 修改dangerSource
     */
    @Log(title = "dangerSource", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskDangerSource riskDangerSource)
    {
        return toAjax(riskDangerSourceService.updateRiskDangerSource(riskDangerSource));
    }

    @Log(title = "dangerSource", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskDangerSourceService.deleteRiskDangerSourceByIds(ids));
    }
}
